package com.chuqiyun.authorization.utils;

import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;

/**
 * @author mryunqi
 * @date 2023/5/20
 */
public class ModUtil {
    /**
    * @Author: mryunqi
    * @Description: 获取域名的一级域名
    * @DateTime: 2023/5/20 20:37
    * @Params: String domain
    * @Return String domain
    */
    public static String getTopLevelDomain(String domain) {
        String[] domainParts = domain.split("\\.");
        if (domainParts.length >= 2) {
            return domainParts[domainParts.length - 2] + "." + domainParts[domainParts.length - 1];
        } else {
            return "";
        }
    }

    /**
    * @Author: mryunqi
    * @Description: 判断对象中属性值是否全为空
    * @DateTime: 2023/5/20 20:43
    */
    public static boolean isNull(Object object) {
        if (null == object) {
            return true;
        }

        try {
            for (Field f : object.getClass().getDeclaredFields()) {
                f.setAccessible(true);

                /*System.out.print(f.getName() + ":");
                System.out.println(f.get(object));*/

                if (f.get(object) != null && StringUtils.isNotBlank(f.get(object).toString())) {
                    return false;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return true;
    }
}
